﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace WeeLibrary.Text
{
    public class HashEncrypt
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="inputStr">被加密字符串</param>
        /// <returns></returns>
        public static string MD5Encrypt(string inputStr)
        {
            byte[] result = Encoding.UTF8.GetBytes(inputStr);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);

            return BitConverter.ToString(output).Replace("-", "");

        }


        /// <summary>
        /// SHA1加密
        /// </summary>
        /// <param name="inputStr">被加密字符串</param>
        /// <returns></returns>
        public static string SHA1Encrypt(string inputStr)
        {
            byte[] result = Encoding.UTF8.GetBytes(inputStr);
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
            byte[] output = sha1.ComputeHash(result);
            return BitConverter.ToString(output).Replace("-", "");

        }


        /// <summary>
        /// 按密码加密方式获取结果
        /// </summary>
        /// <param name="inputStr">被加密字符串</param>
        /// <returns></returns>
        public static string GetPassword(string inputStr)
        {
            return MD5Encrypt(SHA1Encrypt(inputStr));
        }

    }
}
